Accessing current class through $this-> from a function called statically. [PHP]
Posted
by MQA
on Stack Overflow
See other posts from Stack Overflow
or by MQA
Published on 2010-04-22T19:03:18Z
Indexed on
2010/04/22
21:03 UTC
Read the original article
Hit count: 90
This feels a bit messy, but I'd like to be able to call a member function statically, yet have the rest of the class behave normally...
Example:
<?php
class Email
{
private $username = 'user';
private $password = 'password';
private $from = '[email protected]';
public $to;
public function SendMsg($to, $body)
{
if (isset($this))
$email &= $this;
else
$email = new Email();
$email->to = $to;
// Rest of function...
}
}
Email::SendMsg('[email protected]');
How best do I allow the static function call in this example?
Thanks!
© Stack Overflow or respective owner